﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace ImageView
{
	/// <summary>
	/// Interaction logic for MiniKep.xaml
	/// </summary>
	public partial class MiniKep : UserControl
	{
		public MiniKep()
		{
			this.InitializeComponent();
		}

        public static readonly DependencyProperty ImageProperty = DependencyProperty.Register("Image", typeof(ImageSource), typeof(MiniKep));
        public static readonly DependencyProperty ImageTextProperty = DependencyProperty.Register("ImageText", typeof(string), typeof(MiniKep));

        public MouseButtonEventHandler KepMouseDown;

        public ImageSource Image
        {
            get { return (ImageSource)GetValue(ImageProperty); }
            set { SetValue(ImageProperty, value); }
        }

        public string ImageText
        {
            get { return (string)GetValue(ImageTextProperty); }
            set { SetValue(ImageTextProperty, value); }
        }

        private void Container_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (KepMouseDown != null) KepMouseDown(this, e);
        }

        public void SetRotation(string file)
        {
            int rot = App.Shell.GetExifRotationInfo(file);
            ImgRot.Angle = 0;
            ImgScale.ScaleX = 1;
            ImgScale.ScaleY = 1;
            switch (rot)
            {
                case 2:
                    ImgScale.ScaleY = -1;
                    break;
                case 3:
                    ImgRot.Angle = -180;
                    break;
                case 4:
                    ImgScale.ScaleX = -1;
                    break;
                case 5:
                    ImgRot.Angle = 90;
                    ImgScale.ScaleY = -1;
                    break;
                case 6:
                    ImgRot.Angle = 90;
                    break;
                case 7:
                    ImgRot.Angle = -90;
                    ImgScale.ScaleY = -1;
                    break;
                case 8:
                    ImgRot.Angle = -90;
                    break;
            }
        }

        public bool VideoIconVisible
        {
            get { return VideoIcon.IsVisible; }
            set
            {
                if (value) VideoIcon.Visibility = System.Windows.Visibility.Visible;
                else VideoIcon.Visibility = System.Windows.Visibility.Hidden;
            }
        }

	}
}